package com.zeldu.mail.controller;

import com.zeldu.common.exception.CustomException;

import com.zeldu.common.model.response.CommonCode;
import com.zeldu.common.model.response.ResponseResult;
import com.zeldu.common.util.MailUtil;
import com.zeldu.mail.service.SendService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController

public class SendEmail {
    @Autowired
    SendService sendService;
    @RequestMapping ("/send")
    public ResponseResult sendEms(@RequestParam("email") String targetEmail){
         boolean b = MailUtil.checkMail(targetEmail);
         if(!b){
             return new ResponseResult(CommonCode.Email_Wrong);
         }
        try {
            sendService.testSendSimple(targetEmail);
        }catch (Exception e){
            throw new CustomException(CommonCode.FAIL);
        }

        return new ResponseResult(CommonCode.SUCCESS);
    }

}
